package com.qf.deviceconsumeropenfeign9003.controller;

import com.qf.deviceconsumeropenfeign9003.openfeign.DeviceFeign;
import com.qf.java2106.pojo.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author q
 * @version V1.0
 * @date 2022/01/18
 **/
@RestController
@RequestMapping("/consumer/device")
public class DeviceController {

    @Value("${server.port}")
    private String port;

    @Autowired
    DeviceFeign deviceFeign;

    @GetMapping("/var1")
    public String var1(Integer id){
        String result =  deviceFeign.testVar(id);
        return port + "-->" + result;
    }

    @GetMapping("/pathvar1/{name}")
    public String pathvar1(@PathVariable String name){
        String result =  deviceFeign.testUrlVar(name);
        return port + "-->" + result;
    }

    @GetMapping("/var2")
    public String var2(Integer id, String name){
        String result =  deviceFeign.testManyVar(id, name);
        return port + "-->" + result;
    }

    @PostMapping("/json1")
    public Device json1(@RequestBody Device device){
        Device myDevice = deviceFeign.testJson(device);
        myDevice.setId(Integer.parseInt(port));
        return myDevice;
    }

    @PostMapping("/testCookie")
    public String testCookie(@RequestBody Device device,
                             @CookieValue(required = false, name = "login_token") String loginToken) {
        return deviceFeign.testCookie(device);
    }

}
